using UnityEngine;
using System.Collections;

public class Button : MonoBehaviour 
{
	public Texture2D buttonNormal;
	public Texture2D buttonClicked;
	
	public string tag;
	public string level;
	public string currentTag;
	
	public GameObject fadeOut;
	GameObject go;
	
	void Start () 
	{
	
	}
	
	void Update () 
	{
		go = GameObject.Find("Main Camera");
		if(!go.GetComponent<Wait>().isWaiting)
		{
			if(gameObject.tag == "Exit")
			{
				Application.Quit();
			}
			else if(currentTag == gameObject.tag)
			{
				Application.LoadLevel(level);
			}
		}
	}
	
	void OnMouseEnter()
	{
		gameObject.renderer.material.mainTexture = buttonClicked;
	}
	
	void OnMouseExit()
	{
		gameObject.renderer.material.mainTexture = buttonNormal;
	}
	
	void OnMouseDown()
	{			
		fadeOut.gameObject.SetActive(true);
		go.GetComponent<Wait>().StartWaiting(2);
		
		currentTag = gameObject.tag;
	}
}
